<template>
<div>
	<ol class="breadcrumb">
	  <li class="breadcrumb-item">频道管理</li>
	</ol>
	<div class="biaoqing-container">
		<div class="biaoqing-table" >
			<table class="table table-bordered table-hover">
				<thead>
		    		<tr>
				      <th>频道</th>
				      <th>栏目专题</th>
				      <th>操作</th>
				    </tr>
		    	</thead>
		    	<tbody>
		    		<tr v-for="(tag,index) in indexTags.items">
		    			<td style="width:100px;">
		    				{{tag.name}}
		    			</td>
		    			<td>{{tag.child}}</td>
		    			<td style="width:100px;">
							<span @click="editCh(tag.id,tag.child)" class="pass-ing cursor hover-line">修改</span>
		    			</td>
		    		</tr>
		    	</tbody>
			</table>
	    </div>
    </div>
</div>
</template>
<script>
import { Tags } from '../../../resources'
import swal2 from 'sweetalert2'
import querystring from 'querystring'
export default {
	data:() => ({
		loading: false,
		indexTags: ''
	}),
	mounted () {
      	this.$emit('loaded',false)
    },
    beforeRouteEnter (to,form,next) {
		var params = {
			pageSize:20,
		}
		var req = [Tags.index(params)]
		Promise.all(req).then(([indexTags]) => {
    		next(vm => {
    			vm.indexTags = indexTags.data.data;
    		})
		})
	},
	methods: {
		goTags(page){
			var params = {
				pageSize:20,
			}
			var req = [Tags.index(params)]
			Promise.all(req).then(([indexTags]) => {
	    		this.indexTags = indexTags.data.data;
			})
		},
		editCh(id,val){
			var that = this;
			swal2({
			  title: '修改栏目专题',
			  text:'多个专题用 , (英文符号)分割',
			  input: 'text',
			  confirmButtonText: '确定',
			  cancelButtonText: '取消',
			  showLoaderOnConfirm: true,
			  showCancelButton: true,
			  reverseButtons:true,
			  inputValue:val,
			  preConfirm:function(text){
			  	var limit = 0;
			  	if(text!='' && text.indexOf(',')>=0){
			  		var arr = text.split(',');
			  		limit = arr.length;
			  	}
			  	return new Promise(function(resolve,reject){
			  		if(limit > 6){
			  			reject('专题数量不能超过6个')
			  		}else{
			  			var params = {
						  	"id": id,
						  	"child": text
						}
						that.$http.put('/tag',params).then(res => {
							swal2.close()
							if (res.data.code==200) {
								that.goTags(1)
								that.$notice.success(res.data.msg)
							}else{
								that.$notice.error(res.data.msg)
							}
						})
			  		}
					
			  	})
			  }
			}).catch(swal2.noop)
		}
	}
}
</script>